package com.woniuxy.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.woniuxy.yygh.cmn.mapper.DictMapper;
import com.woniuxy.yygh.model.cmn.Dict;
import com.woniuxy.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: dict excel 的监听器
 * <P> Date: 2022/2/28:20:29
 * <P> Description:
 */

public class DistListener extends AnalysisEventListener<DictEeVo> {
    /**
     *
     * TODO 传入mapper调用方法
     */
    private DictMapper dictMapper;

    public DistListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    /**
        * TODO:在调用之前执行 插入数据
    **/
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo, dict);
        dictMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("读取完毕");
    }
}
